home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 18.1 KB | 581 lines | [TEXT/MPS ] |
- // File: UVUAssist.h - MacApp 3.1 compatible version
- //
- // Contains: C++ header file for the V.U. Assistance Hook for MacApp applications
- //
- // Written by: Jim Schneider and Jeroen Schalk
- //
- // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved.
- //
- // Version: 2.0d1
-
- #ifndef __UVUASSIST__
- #define __UVUASSIST__
-
- #if qNeedsVU
-
- // MacApp
-
- #ifndef __UEVENTHANDLER__
- #include "UEventHandler.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- // Toolbox
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
-
- class TControl;
- class TCtlMgr;
- class TGridView;
- class TPopup;
- class TView;
-
- /* ================================================================== */
- /* Constant definitions */
-
- /*
- | This is the idle frequency of VUAssist. By default this
- | is set to give VUAssist a very high idle frequency. Even
- | though VUAssist does nothing with this idle time, this
- | ensures that SystemTask will be called frequently while
- | the context of the application is the current context. In
- | short, this enables Agent VU, which operates at SystemTask
- | while the app's context is current, to operate at maximum
- | efficiency. This maximizes V.U. performance. If, for some
- | reason, you would like to let the app. sleep for longer
- | periods of time, you can increase this value or, better yet,
- | call gVUAssist.SetIdleFreq with the new frequency. Note,
- | however, that this will cause V.U. to run more slowly against
- | the application.
- */
- const long kVUAssistIdleFreq = 1;
-
-
- enum MoleError {
- mNoErr, /* 0 */
- mUnknownSelector,
- mAlreadyOnline,
- mDeferredKilled,
- mOtherVUHost,
- mBadAddress, /* 5 */
- mBadHandle,
- mBadBlockSize,
- mNoKbdDrvr,
- mBigFail,
- mBadTarget, /* 10 */
- mNoCall,
- mNoPendingTask,
- mAppNotFound,
- mNoAppInfo,
- mDriverDeferred, /* 15 */
- mBadDItemIndex,
- mBadItemHdl,
- mCursBusy,
- mBadMenuRank,
- mBadMenuID, /* 20 */
- mBadMenuItemIndex,
- mBadLastMenuItemIndex,
- mHandleTooBig,
- mNoCmdToAbort,
- mRelRespFail, /* 25 */
- mNotSupportedOnThisMac, /* new in 2.0... */
- mCantFindApp,
- mCantLaunchApp,
- mLaunchAppErr,
- mEndErr /* 30 */
- };
-
-
- /* ----------------- VUAssist proc data structures -------------------- */
- /* The following data structures and constants are not used by the mole. They're
- defined for the benefit of the MacApp VUAssist routine. */
-
- enum ViewItems {
- VINotMember, /* not a control or dialog item */
- VIButton, /* TButton - this is the first control */
- VIRadio, /* TRadio */
- VICheckBox, /* TCheckBox */
- VIScrollBar, /* TScrollBar or TSScrollBar - this is the last control */
- VIPopup, /* TPopup */
- VIStatText, /* TStaticText - from here on are dialog items only */
- VIEditText, /* TEditText or TNumberText */
- VIIcon, /* TIcon */
- VIPicture, /* TPicture */
- VITextEdit, /* TTEView or TDialogTEView */
- VIGridItem /* cell of a TGridView */
- };
-
- /* ================================================================== */
-
- /* ----------------- General Mole data structures -------------------- */
- /* The following data structures are used by Agent VU(the Mole). */
-
- /*
- | Selectors for the currently implemented mole routines:
- | At least one 'mole assist' routine has come to depend on these selector values.
- | Therefore, we should make an effort not to change established values when adding new ones.
- | So new UPPER MOLE commands go to the end of the list (right before EmptyDeferred),
- | and new LOWER MOLE commands go before the beginning of the list, as negative numbers.
- */
- enum MoleSelectors {
- /* Lower mole commands: */
- EntMultKeys = -3, /* new in 2.0 */
- SGestalt = -2, /* new in 2.0 */
- AbortPending = -1,
- SStatus = 0,
- GoOff,
- ComeOn,
- SBlock,
- PBlock, /* not currently used by VU */
- SBlkSize, /* not currently used by VU 5 */
- SMouse,
- PMouse,
- EntKey, /* 8 */
- /* Upper mole commands: */
- SMenuInfo, /* 9 */
- SMenuItems, /* 10 */
- SetMItemKey, /* not currently implemented or used */
- SFrontWind,
- SFindWind,
- SWindInfo,
- SFindCtl, /* 15 */
- SCtlInfo,
- SFindDItem,
- SDItemInfo,
- SResPeek,
- SyncSBlock, /* 20 */
- SNextEvent,
- SHBlock,
- PMouseString,
- SIconHeight,
- SScriptInfo, /* 25 */
- SCurrKCHRid,
- LaunchApp, /* new in 2.0 */
- SScrnInfo, /* new in 2.0 */
- SResPiece, /* new in 2.0 */
- EmptyDeferred, /* 30 */
- EndSelect
- };
-
- /* ----------------- Menu related data structures -------------------- */
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct SendMenuInfoParams {
- short menu_rank; /* left-to-right rank in menu bar */
- short menu_ID; /* ID of menu, if known */
- MenuRef menu_hdl; /* MenuRef; handle to MenuInfo record, if known (for popups) */
-
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct SendMenuInfoParams SendMenuInfoParams;
- typedef SendMenuInfoParams *SendMenuInfoParamsPtr;
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct MoleMenuInfo {
- long num_items; /* number of items in the menu */
- long rank; /* in menu bar, left to right */
- long left_edge; /* as extracted from the menu list field */
- short menuID; /* menu ID as known to the menu manager */
- short menuWidth; /* assuming a rectangular menu, the width in pixels
- NOT the position on the screen! */
- short menuHeight; /* assuming a rectangular menu, the height in pixels
- NOT the position on the screen! */
- long enableFlags; /* Least significant bit is one if the menu iteself is
- enabled. Other bits describe the enabled state of
- the first 31 items */
- /*
- | The menu field either has a pointer to the menu title as a pascal string,
- | or the text of the menu title extending off into the buffer
- */
- union {
- unsigned char *Data;
- unsigned char text[1];
- } menuTitle;
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct MoleMenuInfo MoleMenuInfo;
- typedef MoleMenuInfo *MoleMenuInfoPtr;
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct SendMenuItemsParams {
- short menu_rank; /* left-to-right rank in menu bar */
- short menu_ID; /* ID of menu, if known */
- short start_item; /* rank of item in menu to start the block with */
- short stop_item; /* rank of last item in the menu we are interested in */
- MenuRef menu_hdl; /* handle to MenuInfo record, if known (for popups) */
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct SendMenuItemsParams SendMenuItemsParams;
- typedef SendMenuItemsParams *SendMenuItemsParamsPtr;
-
-
-
- /* ----------------- Window related data structures -------------------- */
-
- /*
- | Used in the valid flags field. The valid flags field reflects which of the traits ( fields ) the Mole was able
- | to fill in accurately.
- */
- #define VKIND 0
- #define VWRECT 1
- #define VRANK 2
- #define VFLAGS 3
- #define VVARIANT 4
- #define VCTLCOUNT 5
- #define VTITLE 6
- #define VALERTP 7
- #define VITEMCNT 8
- #define VITEMLIST 9
- #define VPART 10
- #define VKIND_MASK 0x0001
- #define VRECT_MASK 0x0002
- #define VRANK_MASK 0x0004
- #define VFLAGS_MASK 0x0008
- #define VVARIANT_MASK 0x0010
- #define VCTLCNT_MASK 0x0020
- #define VTITLE_MASK 0x0040
- #define VITEMCNT_MASK 0x0080
- #define VPART_MASK 0x0100
- #define VALL_W_MASK 0x007F
- #define VALL_D_MASK 0x00FF
- #define MWD_TITLE_LEN 64
- #define UNSPECIFIED_RANK (-1)
-
- typedef Point SendFindWindowParam; /* point to test, in global coords */
- typedef SendFindWindowParam *SendFindWindowParamPtr;
-
- typedef short *DWindReqPtr;
-
- /* This is the format of the output buffer for SWindInfo calls. */
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct MoleWindowDescriptor {
- short validFlags; /* which of the following have valid data */
- short windowKind; /* as in window record - standard, dialog, system, alert */
- Rect portRect; /* as in window's grafport */
- Rect structRect; /* boundary rect of struct rgn - global coords */
- Rect contentRect; /* boundary rect of content region - global coords */
- short windowPart; /* returned by some calls */
- short windowRank; /* rank in window list, 1->N */
- short windowFlags; /* visible, hilited, go-Away, spare */
- short windowVariant; /* variation code extracted from high byte of window defproc handle */
- short controlCount; /* how many controls in the control list */
- short numItems; /* number of items in item list */
- /*
- | The title field either has a pointer to the window title as a pascal string,
- | or the text of the window title extending off into the buffer
- */
- union {
- unsigned char *text_ptr;
- unsigned char text[256];
- } windowTitle;
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct MoleWindowDescriptor MoleWindowDescriptor;
- typedef MoleWindowDescriptor *MoleWDescPtr;
-
-
- /* ----------------- Control related data structures -------------------- */
-
- #define VCWINDOW 0
- #define VCRECT 1
- #define VCVALUE 2
- #define VCMIN 3
- #define VCMAX 4
- #define VCHILITE 5
- #define VCPART 6
- #define VCRANK 7
- #define VCTITLE 8
- #define VCWINDOWRANK_MASK 0x0001
- #define VCRECT_MASK 0x0002
- #define VCVALUE_MASK 0x0004
- #define VCMIN_MASK 0x0008
- #define VCMAX_MASK 0x0010
- #define VCHILITE_MASK 0x0020
- #define VCPART_MASK 0x0040
- #define VCRANK_MASK 0x0080
- #define VCVARIANT_MASK 0x0100
- #define VCTITLE_MASK 0x0200
- #define VALL_C_MASK 0x03FF
-
- /* standard CDEF IDs */
- #define POPUP_CDEF 63
-
- typedef Point SendFindControlParam; /* point to test, in global coords */
- typedef SendFindControlParam *SendFindControlParamPtr;
-
- /* This is the format of the input buffer for SCtlInfo calls. */
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct SendControlInfoParams {
- short control_rank; /* rank in control list */
- short window_rank; /* rank of owning window amongst visible windows */
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct SendControlInfoParams SendControlInfoParams;
- typedef SendControlInfoParams *SendCtlInfoParamsPtr;
-
- /* This is the format of the output buffer for SCtlInfo calls. */
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct MoleControlDescriptor { /* mole control descriptor */
- short validFlags; /* which of the following have valid data */
- short owner_rank; /* rank of owning window amongst visible windows */
- Rect ctlRect; /* The ctl fileds are copied from the */
- short ctlValue; /* control record */
- short ctlMin;
- short ctlMax;
- short ctlHilite;
- short part; /* filled in on some calls */
- short ctlRank; /* rank in owning window's control List */
- short ctlDefID; /* variation code from def proc handle */
- /*
- | The ctlData field will have different info depending on the ctlDefID.
- | (For backward compatibility, it can't exceed 'short' in length, or else subsequent
- | field offsets change.)
- */
- union {
- short popupMenuID; /* resource ID of popup menu */
- } ctlData;
- /*
- | The title field either has a pointer to the control title as a pascal string,
- | or the text of the control title extending off into the buffer
- */
- union {
- unsigned char *text_ptr;
- unsigned char text[256];
- } ctlTitle;
- /*
- | New field for version 2.0. This field is only valid in Virtual User to the
- | caller of Mole_Transceiver. During ATP response, the menu handle is glued
- | onto the end (yecch) of the control title string.
- */
- MenuRef popupMenuRef; /* valid if there's a popup menu */
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct MoleControlDescriptor MoleControlDescriptor;
- typedef MoleControlDescriptor *MoleCDescPtr;
-
-
- /* ----------------- Dialog related data structures -------------------- */
-
- #define btnCtrlItem 4
- #define chkCtrlItem 5
- #define radCtrlItem 6
- #define resCtrlItem 7
-
- #define RANK_OF_THE_INVISIBLE (-2)
- /* special constant for items which do no fit into any of the other content item categories */
- #define CUSTOM_ITEM (-1)
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct SendDItemInfoParams {
- short item_num; /* index in dialogs item list */
- short window_rank; /* rank of owning window amongst visible windows */
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct SendDItemInfoParams SendDItemInfoParams;
- typedef SendDItemInfoParams *SendDItemInfoPtr;
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct MoleDItemInfo { /* mole dialog item info */
- Rect box; /* item bounding box */
- long ctlRank; /* if a control - then the control's rank in the control list */
- SignedByte itemType; /* item type */
- Boolean item_enabled;
- Boolean has_text;
- short owner_rank;
- short item_num;
- /* The itemData field either has a pointer to the control title as a pascal string,
- or the text of the control itemData extending off into the buffer, OR the
- short short which is the resource ID of the icon or picture assocaited with
- the item. */
- union {
- unsigned char text[256]; /* static, edit, or control title text */
- unsigned char *item_text_ptr;
- short itemResID;
- } itemData;
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct MoleDItemInfo MoleDItemInfo;
- typedef MoleDItemInfo *MoleDItemInfoPtr;
-
-
- /* ----------------- Mole data block structures -------------------- */
-
- #define MOLE_DATA_BLOCKSIZE 512 /* a nice, arbitrary, round number */
- #define ADDITIONAL_MENU_ITEM_DATA 5 /* bytes in a menu item subrec in addition to
- the text of the menu item (dont ask, its ugly) */
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct MoleDataBlock {
- short blockLength; /* blockLength */
- Byte dataBlock[MOLE_DATA_BLOCKSIZE];
- /* the returned packet will only be a long as needed to send the requested data */
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct MoleDataBlock MoleDataBlock;
- typedef MoleDataBlock *MoleDataBlockPtr;
-
-
- /* ----------------- VUAssist classes -------------------- */
-
- class TGridItem : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TGridView *fGridView; /* reference to a TGridView object */
- long fColumn; /* 1 based counter */
- long fRow; /* 1 based counter */
- long fRank; /* (row-1) * rowlength + column */
-
- virtual ~TGridItem();
- // Destructor
-
- virtual void IGridItem(TGridView *theGridView, short rank);
- virtual void GetExtent(VRect& itsExtent);
- virtual void LocalToWindow(VPoint *thePoint);
- };
-
- typedef long (*MoleHookProcPtr)(long select, Ptr input, Ptr output, short *outputSize, long Result);
-
- enum
- {
- uppMoleHookProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Ptr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short *)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long)))
- };
-
- #if USESROUTINEDESCRIPTORS
- typedef UniversalProcPtr MoleHookUPP;
-
- #define CallMoleHookProc(userRoutine, varCode, theWindow, message, param) \
- CallUniversalProc((UniversalProcPtr)(userRoutine), uppMoleHookProcInfo, (varCode), (theWindow), (message), (param))
- #define NewMoleHookProc(userRoutine) \
- (MoleHookUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMoleHookProcInfo, GetCurrentArchitecture())
- #else
- typedef MoleHookProcPtr MoleHookUPP;
-
- #define CallMoleHookProc(userRoutine, varCode, theWindow, message, param) \
- (*(userRoutine))((varCode), (theWindow), (message), (param))
- #define NewMoleHookProc(userRoutine) \
- ((MoleHookUPP) (userRoutine))
- #endif
-
- class TVUAssist : public TEventHandler
- {
- MA_DECLARE_CLASS;
-
- public:
- short fMoleRefNum;
- Boolean fGridItemSupport;
-
- virtual ~TVUAssist();
- // Destructor
-
- virtual void IVUAssist(Boolean gridItemSupport);
- virtual void OpenMoleDriver();
- virtual void SuspendMole();
- virtual void ResumeMole();
- virtual void SetDebuggerHook(MoleHookUPP newHook);
- virtual MoleError MoleAssist(long select, Ptr input, Ptr output, short *outputSize, long intResult);
-
- virtual MoleError DoMenuItems(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual MoleError DoMenuInfo(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual MoleError DoSendWindowInfo(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual MoleError DoFindControl(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual MoleError DoSendControlInfo(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual MoleError DoSendDlogItemInfo(Ptr input, Ptr output, short *outputSize, MoleError Result);
- virtual void FillPopupDesc(MenuRef theMenuHdl, short menuRank, MoleMenuInfoPtr menuDescPtr, short *outputSize);
- virtual MoleError FillPopupItemDesc(MenuRef theMenuHdl, short start, short stop,
- MoleDataBlockPtr menuItemDescPtr, short *outputSize);
- virtual Boolean FillCtrlDesc(MoleCDescPtr CtrlDescPtr, short thePart, short windowRank,
- short ControlRank, TControl *theControl, short *outputSize);
- virtual void ViewRectToWindowRect(Rect *aRect, TView *aView);
- virtual void FillDlogItemDesc(MoleDItemInfoPtr dlogDescPtr, TWindow *window,
- short windowRank, short itemRank, TView *Item,
- short *outputSize, TGridItem *gridItem);
- virtual TWindow *RankToWindow(short rank);
- virtual short WindowToRank(WindowRef WindToFind);
- virtual void GlobalToWindow(TWindow *window, Point Pt, VPoint *VPt);
- virtual void WindowToView(TView *view, VPoint *VPt, Point *Pt);
- virtual TPopup *MenuIDToPopup(short menuID);
- virtual TCtlMgr *PointToControl(TWindow *window, Point Pt, short *rank);
- virtual short ViewCount(TWindow *window, Boolean dlogViewItems);
- virtual short ItemToRank(TWindow *window, TView *view, Boolean dlogViewItems);
- virtual TView *RankToItem(TWindow *window, short rank, Boolean dlogViewItems,
- TGridItem*& gridItem);
- virtual short CountGridItems(TGridView *theGridView);
- virtual ViewItems GetItemType(TView *Item, Boolean dlogViewItems, Boolean gridViewItems);
-
- };
-
- /* ================================================================== */
- /* Variable declarations */
-
- extern TVUAssist *gVUAssist;
-
- #endif // of #if qNeedsVU
-
- #endif // of #ifndef __UVUASSIST__
-